package com.mall.server.service.ums;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.dubbo.api.UmsResourceApi;
import com.mall.model.domain.UmsResource;
import com.mall.model.vo.CommonPage;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author : xyiaao
 * @createDate : 2022/3/31 14:25
 */
@Service
public class UmsResourceService {

    @DubboReference
    private UmsResourceApi umsResourceApi;

    public void create(UmsResource umsResource) {

        umsResource.setCreateTime(new Date());
        umsResourceApi.save(umsResource);
    }

    public void delete(Integer id) {

        umsResourceApi.removeById(id);
    }

    public CommonPage<UmsResource> list(Integer categoryId, String nameKeyword, Integer pageNum, Integer pageSize, String urlKeyword) {

        Page<UmsResource> pageInfo = umsResourceApi.listPage(categoryId, nameKeyword, pageNum, pageSize, urlKeyword);
        return new CommonPage<>(pageInfo);
    }

    public List<UmsResource> listAll() {

        return umsResourceApi.list();
    }

    public void update(UmsResource umsResource) {

        umsResourceApi.updateById(umsResource);
    }

    public UmsResource getUmsResourceById(Integer id) {

        return umsResourceApi.getById(id);
    }

}
